<template>
	<view class="content">
		<!-- 自定义导航栏 -->
		<view>
			<!-- <navbar></navbar> -->
			<u-navbar title="通知信息" :custom-back="reBack">
				<template v-slot:right>
					<view  v-if="roleType == 2">
						<navigator url="/pages/sendNotice/sendNotice">
							<u-icon name="edit-pen"></u-icon>
						</navigator>
					</view>
				</template>
			</u-navbar>
		</view>
		<view class="search">
			<u-search placeholder="搜索" v-model="keyword" :clearabled="true" :show-action="false" input-align="center" @search="toSearch()"></u-search>
		</view>
		<view class="noice_list">
			<view class="notice_item" v-for="notice in list" :key="notice.id" @click="itemClick(notice.id)">
				<image src="/static/notice_icon/notice_logo1.png" v-if="notice.type == 1"></image>
				<image src="/static/notice_icon/notice_logo3.png" v-else-if="notice.type == 2"></image>
				<image src="/static/notice_icon/notice_logo2.png" v-else-if="notice.type == 3"></image>
				<view class="right">
					<view class="tit_a_time">
						<view class="tit">{{notice.title}}</view>
						<view class="start_time">{{notice.createTime}}</view>
					</view>
					<view class="publicher">{{roleType==1 ? notice.nickname : notice.addressee}}</view>
				</view>
			</view>
		</view>
		<u-loadmore :status="status" margin-top="15" margin-bottom="15" @loadmore="loadmore"/> 
	</view>
</template>

<script>
	export default {
		data() {
			return {
				keyword: '',
				list: [],
				
				roleType: 0,
				
				current: 1,
				size: 10,
				pages: 0,
				status: 'loading',
			}
		},
		onReachBottom(){
			if(this.current >= this.pages) return;
			this.status = 'loading';
			this.current++;
			this.getData().then(() => {
				if(this.current >= this.pages) this.status = 'nomore';
				else this.status = 'loading';
			})
		},
		onPullDownRefresh(){
			this.current = 1
			this.list = []
			this.getData().then(() => {
				uni.stopPullDownRefresh()
			})
		},
		onLoad() {
			this.roleType = uni.getStorageSync("roleType")
			this.getData().then(() => {
				if(this.current >= this.pages) this.status = 'nomore';
				else this.status = 'loadmore';
			})
		},
		methods: {
			loadmore(){
				this.status = 'loading';
				this.current++;
				this.getData().then(() => {
					if(this.current >= this.pages) this.status = 'nomore';
					else this.status = 'loading';
				})
			},
			reBack(){
				uni.switchTab({
					url: '/pages/message/message'
				})
			},
			async getData(){
				const res = await this.$myRequest({
					url: "/notice/" + (this.roleType == 1 ? 'list4Student' : 'list4Teacher'),
					data: {
						current: this.current,
						size: this.size,
						title: this.keyword
					}
				})
				res.data.data.records.forEach(n => {
					n.createTime = this.$u.timeFrom(new Date(n.createTime).getTime(),"yyyy-mm-dd hh:MM")
				})
				// 获取页数
				this.pages = res.data.data.pages
				this.list = [...this.list, ...res.data.data.records]
				
			},
			itemClick(id){
				uni.navigateTo({
				    url: '/pages/notice-detail/notice-detail?id=' + id
				});
			},
			toSearch(){
				this.current = 1
				this.list = []
				this.getData()
			}
		}
	}
</script>

<style lang="scss" scoped>
	.slot-wrap {
			display: flex;
			align-items: center;
			/* 如果您想让slot内容占满整个导航栏的宽度 */
			/* flex: 1; */
			/* 如果您想让slot内容与导航栏左右有空隙 */
			/* padding: 0 30rpx; */
		}
	.content{
		padding: 10rpx 20rpx;
		.search{
		}
		.noice_list{
			
			.notice_item{
				display: flex;
				align-items: center;
				image{
					min-width: 80rpx;
					max-width: 80rpx;
					height: 80rpx;
					border-radius: 5rpx;
				}
				.right{
					width: 100%;
					margin-left: 20rpx;
					border-bottom: 1px solid #eee;
					padding: 20rpx 0;
					min-height: 80rpx;
					box-sizing: content-box;
					display: flex;
					flex-direction: column;
					justify-content: space-between;
					.tit_a_time{
						display: flex;
						justify-content: space-between;
						.tit{
							font-size: 26rpx;
							font-weight: 550;
							overflow:hidden; 
							text-overflow:ellipsis;
							display:-webkit-box; 
							-webkit-box-orient:vertical;
							-webkit-line-clamp:2; 
						}
						.start_time{
							color: #ccc;
							font-size: 24rpx;
							min-width: 210rpx;
							max-width: 210rpx;
							text-align: end;
						}
					}
					.publicher{
						font-size: 24rpx;
						max-width: 600rpx;
						color: #ccc;
						overflow: hidden;
						text-overflow:ellipsis;
						white-space: nowrap;
					}
				}
				
			}
		}
	}
	
</style>
